<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://blogs">

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:include href="../main.xsl" />
	<xsl:include href="controls.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/navigation.xsl" />
	<xsl:include href="blocks.xsl" />
	<xsl:include href="blogsBars.xsl" />
	<xsl:include href="rss.xsl" />
	
	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<xsl:call-template name="rss">
				<xsl:with-param name="userLogin">
					<xsl:value-of select="response/@user-login" />
				</xsl:with-param>
			</xsl:call-template>
			<link rel="stylesheet" href="{$baseURI}/css/blogs.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/blogs.js" />
			
			<xsl:comment>[if IE]&gt;&lt;link rel="stylesheet" href="<xsl:value-of select="$baseURI"/>/css/blogs-ie.css" type="text/css" media="all" /&gt;&lt;![endif]</xsl:comment>
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />
			
			<!-- Header -->
			<div id="header">
				<xsl:call-template name="logo" />
				
				<!-- Menu -->
				<xsl:call-template name="menu" />
			</div>
			<!-- /Header -->
			
			<!-- Blocks -->
			<div id="blocks">
				<xsl:call-template name="default-blocks-top" />
				
				<div id="blocks_inner">
					<div class="block">
						<h4>&labelBlockCloud;</h4>
						<p>
							<xsl:apply-templates select="document('xmodule://blogs/getTagsCloud')/data/response" mode="block-tags-cloud" />
						</p>
					</div>
					
					<div class="block">
						<h4>&labelBlockPopular;</h4>
						<p>
							<xsl:apply-templates select="document('xmodule://blogs/getBlogsBlock')/data/response" mode="block-blogs" />
						</p>
					</div>
				</div>
			</div>
			<!-- // Blocks -->
			
			<!-- Content -->
			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			<!-- // Content -->
			
			<!-- Address -->
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	
	
	<!-- RESPONSE -->
	<xsl:template match="response">	
		
		<xsl:if test="$method = 'tag'">
			<div id="tag_search">
				<form action="{$baseURI}/blogs/tag/go" method="post">
					<input id="tag_name" type="text" name="tag">
						<xsl:attribute name="value">
							<xsl:value-of select="@tag-filter" />
						</xsl:attribute>
					</input>
					<xsl:text> </xsl:text>
					<input type="submit" value="→" />
				</form>
			</div>
			<script type="text/javascript">
				$('#tag_name')
					.blur (function () {
						if ($(this).val() == '') {
							$(this)
								.val('&labelInsertTag;')
								.css('color', '#dfdfdf');
						}
					})
					.click (function () {
						if ($(this).val() == '&labelInsertTag;') {
							$(this)
								.val('')
								.css ('color', '#000');
						}
					});
				
				
				if ($('#tag_name').val() == '') {
					$('#tag_name')
						.val('&labelInsertTag;')
						.css('color', '#dfdfdf');
				}
			</script>
		</xsl:if>
		
		<xsl:if test="@blog-id != '0'">
			<div id="blog_info">
				<xsl:apply-templates select="document(concat('xmodule://blogs/getBlog/', @blog-id))/data/response/object" mode="blog-bar" />
			</div>
		</xsl:if>
		
		<xsl:if test="$method = 'user'">
			<xsl:apply-templates select="document(concat('xobject://user/', @user-id))/data/object" mode="personal-blog-bar" />
		</xsl:if>
		
		<xsl:if test="count (object) = 0">
			<div>&labelPostsEmpty;</div>
		</xsl:if>
		
		<xsl:apply-templates select="object" />
		
		<xsl:apply-templates select="pages" mode="pages-navigation">
			<xsl:with-param name="href">
				<xsl:value-of select="$baseURI" />
				<xsl:text>/blogs</xsl:text>
				<xsl:if test="$method != '__default'">
					<xsl:text>/</xsl:text>
					<xsl:value-of select="$method" />
				</xsl:if>
				<xsl:if test="@blog-name != ''">
					<xsl:text>/blog/</xsl:text>
					<xsl:value-of select="@blog-name" />
				</xsl:if>
				<xsl:if test="@user-login != ''">
					<xsl:text>/</xsl:text>
					<xsl:value-of select="@user-login" />
				</xsl:if>
				<xsl:if test="@tag-filter != ''">
					<xsl:text>/</xsl:text>
					<xsl:value-of select="@tag-filter" />
				</xsl:if>
			</xsl:with-param>
		</xsl:apply-templates>
	</xsl:template>
	
	<xsl:template match="object[@type='article']">
		<xsl:param name="countTags" select="count (property[@name='tags']/value)" />
		<xsl:param name="blogAlias" select="property[@name='blog_alias']/value" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		
		<div class="post">
			<h2>
				<xsl:if test="property[@name='draft']/value = '1'">
					<div>
						<img src="{$baseURI}/images/post-closed.png" title="&labelDraft;" alt="" />
					</div>			
				</xsl:if>
				<xsl:if test="property[@name='blog_id']/value != '0'">
					<a class="post_blog_header" href="{$baseURI}/blog/{$blogAlias}">
						<xsl:value-of select="property[@name='blog_title']/value" />
					</a>
				</xsl:if>
				<xsl:if test="property[@name='blog_id']/value = '0'">
					<a class="post_blog_header personal" href="{$baseURI}/blogs/user/{$userLogin}">
						<xsl:text>&labelBlogOf; </xsl:text>
						<xsl:value-of select="property[@name='user_name']/value" />
					</a>
				</xsl:if>
				<div>→</div>
				<a href="{$baseURI}/post/article/{@id}">
					<xsl:value-of select="property[@name='title']/value" disable-output-escaping="yes" />
				</a>
				<a title="&labelComments;" class="post_comments" href="{$baseURI}/post/article/{@id}#comments">
					<xsl:value-of select="property[@name='count_comments']/value" />
				</a>
			</h2>
			<div class="post_body">
				<div class="post_body_inner">
					<xsl:value-of select="property[@name='text']/value" disable-output-escaping="yes" />
				</div>
			</div>
			<div class="post_tags">
				<xsl:for-each select="property[@name='tags']/value">
					<a>
						<xsl:attribute name="href">
							<xsl:value-of select="concat ($baseURI, '/blogs/tag/', .)" />
						</xsl:attribute>
						<xsl:value-of select="." />
					</a>
					<xsl:if test="position() != $countTags">
						<xsl:text>, </xsl:text>
					</xsl:if>
				</xsl:for-each>
			</div>
			<div class="post_info">
				<div class="post_info_inner">
					<xsl:call-template name="article-options" select="." />
				</div>
			</div>
		</div>
	</xsl:template>
	
	<xsl:template match="object[@type='link']">
		<xsl:param name="countTags" select="count (property[@name='tags']/value)" />
		<xsl:param name="blogAlias" select="property[@name='blog_alias']/value" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		
		<div class="post">
			<h2>
				<xsl:if test="property[@name='draft']/value = '1'">
					<div>
						<img src="/images/post-closed.png" title="&labelDraft;" alt="" />
					</div>			
				</xsl:if>
				<xsl:if test="property[@name='blog_id']/value != '0'">
					<a class="post_blog_header" href="{$baseURI}/blog/{$blogAlias}">
						<xsl:value-of select="property[@name='blog_title']/value" />
					</a>
				</xsl:if>
				<xsl:if test="property[@name='blog_id']/value = '0'">
					<a class="post_blog_header personal" href="{$baseURI}/blogs/user/{$userLogin}">
						<xsl:text>&labelBlogOf; </xsl:text>
						<xsl:value-of select="property[@name='user_name']/value" />
					</a>
				</xsl:if>
				<div>→</div>
				<div class="link_image">
					<img src="{$baseURI}/images/post-link.png" alt="" />
				</div>
				<a class="link">
					<xsl:attribute name="href">
						<xsl:value-of select="concat ($baseURI, '/blogs/link/', @id)" />
					</xsl:attribute>
					<xsl:value-of select="property[@name='title']/value" disable-output-escaping="yes" />
				</a>
				<a title="&labelComments;" class="post_comments" href="{$baseURI}/post/link/{@id}#comments">
					<xsl:value-of select="property[@name='count_comments']/value" />
				</a>
			</h2>
			<div class="post_body">
				<div class="post_body_inner">
					<xsl:value-of select="property[@name='description']/value" disable-output-escaping="yes" />
				</div>
			</div>
			<div class="post_tags">
				<xsl:for-each select="property[@name='tags']/value">
					<a>
						<xsl:attribute name="href">
							<xsl:value-of select="concat ($baseURI, '/blogs/tag/', .)" />
						</xsl:attribute>
						<xsl:value-of select="." />
					</a>
					<xsl:if test="position() != $countTags">
						<xsl:text>, </xsl:text>
					</xsl:if>
				</xsl:for-each>
			</div>
			<div class="post_info">
				<div class="post_info_inner">
					<xsl:call-template name="article-options" select="." />
				</div>
			</div>
		</div>
	</xsl:template>
	
</xsl:stylesheet>